
/*
* InventoryDAL
*/
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Carmall.Entity;
using Carmall.IDAL;

namespace Carmall.DAL
{
	/// <summary>
	/// Inventory DAL 的摘要说明。
	/// </summary>
	public class Inventory : BaseDAL<InventoryInfo>, IInventory
	{
		#region 对象实例及构造函数

		public static Inventory Instance
		{
			get
			{
				return new Inventory();
			}
		}
		public Inventory() : base("inventory","ID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override InventoryInfo DataReaderToEntity(IDataReader dataReader)
		{
			InventoryInfo inventoryInfo = new InventoryInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			
			inventoryInfo.ID = reader.GetInt32("ID");
			inventoryInfo.ProductID = reader.GetInt32("ProductID");
			inventoryInfo.Quantity = reader.GetInt32("Quantity");
			inventoryInfo.Type = reader.GetInt32("Type");
			inventoryInfo.Created = reader.GetDateTime("Created");
			inventoryInfo.UserID = reader.GetInt32("UserID");

			
			return inventoryInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
		protected override Hashtable GetHashByEntity(InventoryInfo obj)
		{
			InventoryInfo info = obj as InventoryInfo;
			Hashtable hash = new Hashtable(); 
			
			
			hash.Add("ID", TypeHelper.SafeInt(info.ID));
			hash.Add("ProductID", TypeHelper.SafeInt(info.ProductID));
			hash.Add("Quantity", TypeHelper.SafeInt(info.Quantity));
			hash.Add("Type", TypeHelper.SafeInt(info.Type));
			hash.Add("Created", TypeHelper.SafeTime(info.Created));
			hash.Add("UserID", TypeHelper.SafeInt(info.UserID));

			
			return hash;
		}
	}
}
